import json
import pygal.maps.world
from country_code import get_country_code

#将数据加载到一个列表中
filename = 'population.json'
with open(filename) as f:
    pop_data = json.load(f)
#创建一个包含人口数量的字典
cc_populations = {}
#打印每个国家2018年的预估人口
for pop_dict in pop_data:
    if pop_dict["Year"] == 2015:
        country = pop_dict["Country Name"]
        population = pop_dict["Value"]
        code = get_country_code(country)
        if code:
            cc_populations[code] = population
            print(country+": "+str(population))
print(cc_populations)
#开始绘制世界地图
wm = pygal.maps.world.World()
wm.title = "The World Map Population Of 2016"
wm.add('2016',cc_populations)
wm.render_to_file("world_map.svg")